*-------------------------------------------------------------------------------
* Set the critical parameters of the computing environment
*-------------------------------------------------------------------------------

	macro drop _all
	
	set more off
	set graphics off
	
	
	global	directory	`"/Volumes/GoogleDrive/My Drive/02_Stanford/00_Researching/16_SocialScientization/-01_SSH/00_replication/"'
	global	data		"${directory}00_data/"
	global	visuals		"${directory}02_visuals/"
	global		axes ///
				ysc(lc(none) ) ///
				xsc(lc(none) ) ///
				xlab(, labc(gs10) tlc(gs10) tlw(medthick) labsize($asize )) ///
				ylab(, labc(gs10) tlc(gs10) tlw(medthick) nogrid labsize($asize )) ///
				note("") ///
				legend(size($lsize )) ///
				plotregion(lc(gs10) lw(medthick)) ///
				graphregion(margin(zero)) xti("")

	
	
	
		
*-------------------------------------------------------------------------------
* Figure 2
*-------------------------------------------------------------------------------
	
	***********************************
	* ! ! !  A T T E N T I O N  ! ! ! *
	***********************************
	
	* ASSUMES UK SPEECH DATA IS ALREADY LOADED*
	
	cap drop yr_tag
	egen yr_tag = tag(year)
	cap drop yr_len
	egen yr_len = mean(length), by(year)

	
		tw	(hist year if year < 1910 ///
				, yscale(alt) ///
				freq discrete ///
				fc(white) lw(vthin) lc(gs6) ///
				yti("{it:N} Speeches" "per Year", orientation(horizontal)) ///
				ylab(0 "0" 1.0e+04 "10K" 2.0e+04 "20K" 3.0e+04 "30K" 4.0e+04 "40K" 5.0e+04 "50K", labc(gs10)))  ///
			(line yr_len year if year < 1910 ///
				, yaxis(2) ///
				yscale(alt axis(2) lc(gs10)) ///
				ylab(0(50)200, labc(gs10) tlc(gs10) axis(2) nogrid) ///
				yti("Avg. Terms" "per Speech", orientation(horizontal) axis(2)) ///
				lp(solid) lw(thin)) ///
			, legend(off) ///
			xti("") ///
			$axes ///
			xlabel(1800(10)1910, angle(45))
								

		gr export "${visuals}fig2.tif", width(1200) replace

		
		
		
*-------------------------------------------------------------------------------
* Figure 3
*-------------------------------------------------------------------------------
	cap drop decade
	egen decade = cut(year), at(1800(10)1910)

	cap drop dec_tag
	egen dec_tag = tag(decade)
	
	
	global	sch 	sch_educ ///
					sch_school ///
					sch_instruct ///
					sch_teach sch_teacher ///
					sch_train ///
					sch_scholar ///
					sch_child ///
					sch_pupil
					
					
					
	foreach var in $sch {
		cap drop dec_`var'
		egen dec_`var' = sum(`var'), by(decade)
		}
	

	sort decade 

		tw	(line dec_sch_school decade if dec_tag == 1, lc(black) lw(medthick)) ///
			(line dec_sch_educ decade if dec_tag == 1, lc(black) lw(medthick)) ///
			(line dec_sch_instruct decade if dec_tag == 1, lc(black) lw(medthick)) ///
			(line dec_sch_train decade if dec_tag,  lc(black) lw(medthick) ) ///
			, xlabel(1800(30)1920, nogrid angle(45) labsize(large) ) ///
				ylabel(50000 "50K" 40000 "40K" 30000 "30K" 20000 "20K" 10000 "10K" 0 "0", nogrid labsize(large)) ///
				xt("") ///
				legend(order(	1 "school" ///
								2 "educ" ///
								3 "instruct" ///
								4 "train") ///
						pos(10) bmargin(vlarge) ring(0) size(large)) aspect(1) ///
			$axes
								
		gr save "${visuals}fig3_left.gph", replace
		
		
		tw	(sc dec_sch_scholar decade if dec_tag, recast(connected) m(+)  mc(black) lc(black) lp(solid) msize(medium)) ///
			(sc dec_sch_child decade if dec_tag, recast(connected) m(O) mc(black)  lc(black) lp(solid) msize(medium)) ///
			(sc dec_sch_teach decade if dec_tag == 1, recast(connected) m(Oh) mc(black) lc(black) lp(solid) msize(medium)) ///			
			(sc dec_sch_pupil decade if dec_tag,  recast(connected) m(Sh) mc(black) lc(black) lp(solid) msize(medium)) ///
			(sc dec_sch_teacher decade if dec_tag, recast(connected) m(S)  mc(black) lc(black) lp(solid) msize(medium)) ///
			, xlabel(1800(30)1920, nogrid angle(45) labsize(large)) ///
				ylabel(10000 "10K" 8000 "8K" 6000 "6K" 4000 "4K" 2000 "2K" 0 "0", nogrid labsize(large)) ///
				xt("") ///
				legend(order(	5 "teacher" ///
								2 "child" ///
								3 "teach" ///
								4 "pupil" ///
								1 "scholar" ) ///
						pos(10) bmargin(vlarge) ring(0) size(large)) aspect(1) ///
			$axes
								
		gr save "${visuals}fig3_right.gph", replace
		
		
* Combine graphs 
		gr combine "${visuals}fig3_left.gph" "${visuals}fig3_right.gph", row(1) 
		gr export "${visuals}fig3.pdf", replace
		gr export "${visuals}fig3.tif", width(1200) replace
		
		
* Clean up directory 
		erase "${visuals}fig3_right.gph" 
		erase "${visuals}fig3_left.gph"



*-------------------------------------------------------------------------------
* Figure 4
*-------------------------------------------------------------------------------
	clear
	use "${data}uk_ivs.dta"
	global	directory	`"/Volumes/GoogleDrive/My Drive/02_Stanford/00_Researching/16_SocialScientization/-01_SSH/00_replication/"'
	global	data		"${directory}00_data/"
	global	visuals		"${directory}02_visuals/"
	global	axes ///
			ysc(lc(gs10)) ///
			xsc(lc(gs10)) ///
			xlab(, labc(gs10) tlc(gs10)) ///
			ylab(, labc(gs10) tlc(gs10) nogrid) ///
			ti("") note("")	
	
* Left panel
		
		tw 	(line wst_agency year if year < 1910, lc(black)) ///
			(line wst_census year if year < 1910, lc(black) ) ///
			(line wst_yrbkpub year if year < 1910, lc(black)) ///
			, ///
			xlabel(1800(10)1910, angle(45) nogrid labsize(medium)) ///
			ylab(, nogrid labsize(medium)) ///
			xti("") ///
			yti("") ///
			legend(	order(	1 "National statistics agency" ///
							2 "National census ever" "conducted" ///
							3 "Concurrent national" "population statistics" "yearbook") ///
					pos(10) ring(0) bmargin(small) size(medsmall) ///
					title("Prop. of states with", size(medium)) ///
					region(fcolor(none))) ///
			$axes
					
					
		gr save "${visuals}fig4_left.gph", replace
		

* Right panel, top
		tw 	(line committees year if year < 1910 & year > 1830, lc(black)) ///
			(line journals year if year < 1910 & year > 1830, lc(black)) ///
			(line int_meetings year if year < 1910 & year > 1830, lc(black)), ///
			xlabel(1830(10)1910, angle(45) nogrid labsize(vlarge)) ///
			ylab(0(20)80, nogrid labsize(vlarge)) ///
			xti("") ///
			yti("") ///
			legend(	order(	1 "No. of active research committees in the" "British Association for the Advancement" "of Science (BAAS)" ///
							2 "No. of European population statistics" "journals in circulation" ///
							3 "Cum. No. of International" "Statistics Congresses") ///
					pos(10) ring(0) bmargin(small) size(medsmall) region(color(none))) ///
			$axes
					
		gr save "${visuals}fig4_right_top.gph", replace
		
* Right panel, bottom
		line 	fellows year if year < 1910  & year > 1833, ///
				xlabel(1830(10)1910, angle(45) nogrid labsize(vlarge)) ///
				ylab(, nogrid labsize(vlarge)) ///
				xti("") ///
				yti("") ///
				text(1000 1855 "No. of Fellows in the London" "(Royal) Statistical Society", size(medlarge)) ///
			$axes
			
		gr save "${visuals}fig4_right_bot.gph",  replace
		
		
* Combine graphs into one
		gr combine "${visuals}fig4_right_top.gph" "${visuals}fig4_right_bot.gph", col(1)
		gr save "${visuals}fig4_right.gph", replace
		
		gr combine "${visuals}fig4_left.gph" "${visuals}fig4_right.gph"
		gr export "${visuals}fig4.tif", width(1200) replace
		
* Clean up directory
		erase "${visuals}fig4_left.gph" 
		erase "${visuals}fig4_right.gph" 
		erase "${visuals}fig4_right_top.gph" 
		erase "${visuals}fig4_right_bot.gph"
		
	
*-------------------------------------------------------------------------------
* Figure A-1
*-------------------------------------------------------------------------------


* Top Panel 

	clear
	use "${data}west_vdem10.dta"
		
	drop if year > 1910

	cap drop state
	sort country_name
	encode(country_name), gen(state)

	xtset state year
		
	xtline state if year < 1910, overlay  ///
		xti("") xlab(1800(10)1910, angle(45) nogrid labc(white) tlc(white) labsize(minuscule)) xscale(r(1775(10)1910) lc(white)) ///
		yti("") ylabel("") yscale(lstyle(none)) ///
		legend(off) ///
		  text( 1.2  1785 "Austria" , size(vsmall)) ///
          text( 2.2  1785 "Baden" , size(vsmall)) ///
          text( 3.2  1785 "Bavaria" , size(vsmall)) ///
          text( 4.2  1785 "Belgium" , size(vsmall)) ///
          text( 5.2  1785 "Brunswick" , size(vsmall)) ///
          text( 6.2  1785 "Bulgaria" , size(vsmall)) ///
          text( 7.2  1785 "Canada" , size(vsmall)) ///
          text( 8.2  1785 "Denmark" , size(vsmall)) ///
          text( 9.2  1785 "Finland" , size(vsmall)) ///
         text( 10.2  1785 "France" , size(vsmall)) ///
         text( 11.2  1785 "Germany" , size(vsmall)) ///
         text( 12.2  1785 "Greece" , size(vsmall)) ///
         text( 13.2  1785 "Hamburg" , size(vsmall)) ///
         text( 14.2  1785 "Hanover" , size(vsmall)) ///
         text( 15.2  1785 "Hesse-Darmstadt" , size(vsmall)) ///
         text( 16.2  1785 "Hesse-Kassel" , size(vsmall)) ///
         text( 17.2  1785 "Hungary" , size(vsmall)) ///
         text( 18.2  1785 "Iceland" , size(vsmall)) ///
         text( 19.2  1785 "Italy" , size(vsmall)) ///
         text( 20.2  1785 "Luxembourg" , size(vsmall)) ///
         text( 21.2  1785 "Malta", size(vsmall)) ///
         text( 22.2  1785 "Mecklenburg Schwerin" , size(vsmall)) ///
         text( 23.2  1785 "Modena" , size(vsmall)) ///
         text( 24.2  1785 "Montenegro" , size(vsmall)) ///
         text( 25.2  1785 "Nassau" , size(vsmall)) ///
         text( 26.2  1785 "Netherlands" , size(vsmall)) ///
         text( 27.2  1785 "Norway" , size(vsmall)) ///
         text( 28.2  1785 "Oldenburg" , size(vsmall)) ///
         text( 29.2  1785 "Papal States" , size(vsmall)) ///
         text( 30.2  1785 "Parma" , size(vsmall)) ///
         text( 31.2  1785 "Piedmont-Sardinia" , size(vsmall)) ///
         text( 32.2  1785 "Poland" , size(vsmall)) ///
         text( 33.2  1785 "Portugal" , size(vsmall)) ///
         text( 34.2  1785 "Romania" , size(vsmall)) ///
         text( 35.2  1785 "Russia" , size(vsmall)) ///
         text( 36.2  1785 "Saxe-Weimar-Eisenach" , size(vsmall)) ///
         text( 37.2  1785 "Saxony", size(vsmall))  ///
         text( 38.2  1785 "Serbia" , size(vsmall)) ///
         text( 39.2  1785 "Spain" , size(vsmall)) ///
         text( 40.2  1785 "Sweden" , size(vsmall)) ///
         text( 41.2  1785 "Switzerland" , size(vsmall)) ///
         text( 42.2  1785 "Tuscany" , size(vsmall)) ///
         text( 43.2  1785 "Two Sicilies" , size(vsmall)) ///
         text( 44.2  1785 "United Kingdom" , size(vsmall)) ///
         text( 45.2  1785 "United States of America" , size(vsmall)) ///
         text( 46.2  1785 "Wuertemberg" , size(vsmall)) ///
		 scheme(s1mono) plotregion(color(white)) ///
			ysc(lc(none)) 
			 
		gr save "${visuals}figA1_top.gph", replace
		

* Bottom Panel 
	clear 
	use "${data}uk_ivs.dta"
	
	
	sc wst_n_states year if year < 1910, connect(l) ///
			xlabel(1800(10)1910, angle(45) nogrid labsize(medium)) xti("") ///
			ylabel(, nogrid) yti("{it:N} states", orientation(horizontal)) ///
			$axes
			
	gr save "${visuals}figA1_bot.gph", replace
	
	

	gr combine "${visuals}figA1_top.gph" "${visuals}figA1_bot.gph", col(1) ysize(18) xsize(12)
	gr export "${visuals}figA1.tif", width(1200) replace
	
* Clean up

	erase "${visuals}figA1_bot.gph"
	erase "${visuals}figA1_top.gph"
	
set graphics on	
clear all
